package com.banyuan.lesson.stringbuilder;

//前身是StringBuffer，缺点如果不需要并发，效率比较低；
//StringBuilder，在不需要并发的情况下，优先使用；
public class Define {
    public static void main(String[] args) {

        long start = System.currentTimeMillis();
        String s2 = "";
        for (int i = 0; i <10000 ; i++) {
            s2 += "abc";
        }
        long end = System.currentTimeMillis();
        System.out.println(end - start);


        long start2 = System.currentTimeMillis();
        StringBuilder sb2 = new StringBuilder();
        for (int i = 0; i <10000 ; i++) {
            sb2.append("abc");
        }
        long end2 = System.currentTimeMillis();
        System.out.println(end2 - start2);

        //StringBuilder是一个可变的字符串，因此效率要高很多；
        //InvokeDynamic动态调用；

        //reverse方法，对StringBuilder中的内容进行反转
        //StringBuilder中的substring方法不会对原来的StringBuilder进行改变

        StringBuilder stringBuilder1 = new StringBuilder();
        StringBuilder stringBuilder2 = new StringBuilder("23134");
        stringBuilder1.append("sdf");
        System.out.println(stringBuilder1);
    }
}
